package com.bsoft.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bsoft.pojo.UserDo;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

@Mapper

@CacheConfig(cacheNames = "users")
public interface UserMapper extends BaseMapper<UserDo> {
    @Cacheable(key = "#id")
    UserDo selectById(Integer id);

    @CachePut(key = "#user.id")
    default UserDo insert0(UserDo userDo) {
        //插入记录
        this.insert(userDo);
        //返回用户
        return userDo;
    }

    @CacheEvict(key = "#id")
    int deleteById(Integer id);
}
